/*
 * File Name：PayDetailContainer.java
 * Copyright：Copyright 2008-2014 CiWong.Inc. All Rights Reserved.
 * Description： PayDetailContainer.java
 * Modify By：jejun
 * Modify Date：2014-6-11
 * Modify Type：Add
 */
package com.ciwong.mobilepay.view;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils.TruncateAt;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 支付详情
 * 
 * 
 * @author jejun
 * @version ciwong v.1.0 2014-6-11
 * @since ciwong v.1.0
 */
public class PayDetailContainer extends LinearLayout
{
    public static final int payDetailIcon = 0xff0f01;//习网LOGO

    public static final int payDetailName = 0xff0f02;//名称

    public static final int payDetailPrice = 0xff0f03;//价格

    public static final int payDetailNumber = 0xff0f04;//数量

    public static final int payDetailTotal = 0xff0f05;//合计

    public PayDetailContainer(Context context)
    {
        super(context);
        init();
    }

    private void init()
    {
    	//整体是个线性布局
        ViewGroup.LayoutParams vlp = new ViewGroup.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        setBackgroundColor(Color.WHITE);
        setGravity(Gravity.CENTER_VERTICAL);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        int padding = (int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 15, dm);
        setPadding(padding, padding, padding, padding);
        setLayoutParams(vlp);

        ImageView payDetailIcon = new ImageView(getContext());
        payDetailIcon.setId(PayDetailContainer.payDetailIcon);
        LayoutParams lp = new LayoutParams((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 60, dm),
                (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                        60, dm));
        lp.rightMargin = (int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 15, dm);
        addView(payDetailIcon);
        payDetailIcon.setLayoutParams(lp);

        LinearLayout container = new LinearLayout(getContext());
        container.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));
        container.setBackgroundColor(Color.WHITE);
        container.setOrientation(LinearLayout.VERTICAL);
        addView(container);

        LinearLayout ll = new LinearLayout(getContext());
        ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));
        container.addView(ll);

        TextView payDetailName = new TextView(getContext());
        payDetailName.setId(PayDetailContainer.payDetailName);
        lp = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 3.0f);
        lp.rightMargin = (int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 8, dm);
        payDetailName.setEllipsize(TruncateAt.END);
        payDetailName.setSingleLine(true);
        payDetailName.setTextColor(Color.BLACK);
        payDetailName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        payDetailName.getPaint().setFakeBoldText(true);
        ll.addView(payDetailName);
        payDetailName.setLayoutParams(lp);

        TextView payDetailPrice = new TextView(getContext());
        payDetailPrice.setId(PayDetailContainer.payDetailPrice);
        payDetailPrice.setGravity(Gravity.RIGHT);
        payDetailPrice.setLayoutParams(new LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        payDetailPrice.setTextColor(0xff747474);
        ll.addView(payDetailPrice);
        payDetailPrice.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);

        TextView payDetailNumber = new TextView(getContext());
        payDetailNumber.setId(PayDetailContainer.payDetailNumber);
        lp = new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT);
        // lp.bottomMargin = (int) TypedValue.applyDimension(
        // TypedValue.COMPLEX_UNIT_DIP, 5, dm);
        // lp.topMargin = lp.bottomMargin;
        payDetailNumber.setTextColor(0xff747474);
        container.addView(payDetailNumber);
        payDetailNumber.setLayoutParams(lp);
        payDetailNumber.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);

        TextView payDetailTotal = new TextView(getContext());
        payDetailTotal.setId(PayDetailContainer.payDetailTotal);
        payDetailTotal.setLayoutParams(lp);
        payDetailTotal.setTextColor(0xff747474);
        container.addView(payDetailTotal);
        payDetailTotal.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);

    }
}
